<?php
session_start();
require_once("../config.php");
require_once($a_fmSql);
require_once($a_fmConnect);
require_once($a_fcMail);

if (isset($_POST)) {
	if (isset($_POST['valide_inscription']) && $_POST['valide_inscription']=="Inscription") {
		unset($_SESSION['erreur_formulaire']);
		if (isset($_POST['prenom']) && !empty($_POST['prenom']) && isset($_POST['nom']) && !empty($_POST['nom']) && isset($_POST['mail']) && !empty($_POST['mail']) && isset($_POST['password']) && !empty($_POST['password']) && isset($_POST['password_confirm'])) {
			if(preg_match("/^(.+)@(.+)\\.(.+)$/u",$_POST['mail']))
			{
				if($_POST['password_confirm'] == $_POST['password'])
				{
					sql_add_user($_POST['prenom'],$_POST['nom'],$_POST['mail'],$_POST['password']);
					header('Location: ../creation_profil.php');
				}
				else
				{
					$_SESSION['erreur_formulaire'] = "Erreur de confirmation du password";
					header('Location: '.$_SERVER['HTTP_REFERER'].'');
				}
			}
			else
			{
				$_SESSION['erreur_formulaire'] = "E-mail invalide";
				header('Location: '.$_SERVER['HTTP_REFERER'].'');
			}
		}
		else
		{
			$_SESSION['erreur_formulaire'] = "Tous les champs ne sont pas remplis";
			header('Location: '.$_SERVER['HTTP_REFERER'].'');
		}
	}
}
?>